<template>
	<view>
		
		<view style="width: 90%; margin: 200rpx auto;">  <!-- 200rpx  == 100px -->
		<view style=" margin-bottom: 70rpx; font-size: 60rpx; color: royalblue; text-align: center;">登 录</view>
		<uni-forms ref="form" :modelValue="form" :rules="rules">
			<uni-forms-item name="userPhone">
				<uni-easyinput v-model="form.userPhone" prefixIcon="phone" placeholder="请输入手机号"></uni-easyinput>
			</uni-forms-item>
		
			<uni-forms-item name="password">
				<uni-easyinput type="password" v-model="form.password" prefixIcon="locked" placeholder="请输入登录密码"></uni-easyinput>
			</uni-forms-item>
		</uni-forms>
			
		<view>
			<button type="primary" @click="login">登 录</button>
		</view>
		<navigator @click="regirect"  style="margin: 40rpx 0; color: deepskyblue;">前往注册</navigator>
		<navigator @click="forgetPwg" style="float: right; margin: -80rpx 0; color: deepskyblue;">忘记密码</navigator>
	</view>
	</view>
</template>
<!-- 		<u-button @click="save" class="button">
		    保存
		</u-button> -->
<script>
	export default {
		data() {
			return {
				URL:'http://localhost:9000/',//主域名
				form: {userPhone: '', password: ''},
				rules: {
					userPhone: {
						rules: [{required: true, errorMessage: '请输入用户名'}],
						validateTrigger:'submit'
					},
					password: {
						rules: [{required: true, errorMessage: '请输入密码'}],
						validateTrigger:'submit'
					},
				}
			}
		},
		methods: {
			
			//跳转忘记密码页面
			forgetPwg(){
				uni.navigateTo({
					url:"forgetPwg"
				})
			},
			
			//跳转注册页面
			regirect(){
				uni.navigateTo({
					url:"register"
				})
			},
			
			//登陆
			login() {
				uni.request({
					url:this.URL+"user/user/user/login",
					method: 'POST',
					data:this.form,
					success: (res) => {
						if(res.data.code == 20000){
							console.log(res)
							
							uni.setStorageSync("user" , res.data.data.user)
							//登陆成功提示信息
							uni.showToast({
								icon: "none",
								title: '登陆成功',
							})
							//跳转页面
							uni.switchTab({
								url:"personal"
							})
						}
					}
				})
				
			}
		}
	}
</script>

<style>

</style>
